import connect from '../db/connect';
import * as dateTools from '../utils/dateTool';

/**
 * 获取用户信息
 * @param {*} params {id: 用户ID}
 */
function add(params = {}) {
	const { data } = params;
	const { name, phone, company_name, tick_type, representative_name } = data || {};
	let SQL = 'insert into user_info (name, phone, company_name, tick_type, representative_name, sign_state) values ';
	SQL += `('${name}', '${phone}', '${company_name}', ${tick_type}, '${representative_name || 0}', 0)`;
	return new Promise((resolve, reject) =>
		connect({
			SQL,
			resolve,
			reject
		})
	);
}

function select(params = {}) {
	const { data } = params;
	const { phone } = data || {};
	let SQL = `select * from user_info where phone = '${phone}'`;
	return new Promise((resolve, reject) =>
		connect({
			SQL,
			resolve,
			reject
		})
	);
}

function selectById(params = {}) {
	const { id } = params;
	let SQL = `select * from user_info where id = ${id}`;
	return new Promise((resolve, reject) =>
		connect({
			SQL,
			resolve,
			reject
		})
	);
}

export { add, select, selectById };
